package cn.rwklyd.ecommerce.mapper;

import cn.rwklyd.ecommerce.pojo.Cart;
import cn.rwklyd.ecommerce.pojo.Product;
import cn.rwklyd.ecommerce.pojo.UserLog;
import cn.rwklyd.ecommerce.pojo.Users;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author 键盘书生
 * @date 2024/12/3
 */
@Mapper
public interface AdminMapper {
    //查询所有商品信息
    @Select("select * from products")
    List<Product> productList();

    //添加商品信息
    @Insert("insert into products(name,description,price,stock,image_url,sort) values(#{name},#{description},#{price},#{stock},#{imageUrl},#{sort})")
    Boolean addProduct(Product product);

    //删除商品信息
    @Delete("delete from products where product_id=#{productId}")
    Boolean deleteProduct(String productId);

    //修改商品信息
    @Update("update products set name=#{name},description=#{description},price=#{price},stock=#{stock},image_url=#{imageUrl},sort=#{sort} where product_id=#{productId}")
    Boolean updateProduct(Product product);

    //查询全部订单
    @Select("select * from cart")
    List<Cart> queryOrderList();

    //查询全部用户(role=customer)
    @Select("select * from users where role='customer'")
    List<Users> queryUserList();

    //查询用户日志(id)
    @Select("select * from user_log where user_id=#{id} ORDER BY action_time DESC")
    List<UserLog> queryUserLog(String id);

}
